#!/usr/bin/env python3
# -*- coding: utf-8 -*-
# File  : base64转图片.py
# Author: DaShenHan&道长-----先苦后甜，任凭晚风拂柳颜------
# Date  : 2022/12/9
import base64

import requests
from io import BytesIO
from PIL import Image

def main():
    headers = {
        'referer':'https://files.yuchenglw.com',
        # 'user-agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/108.0.0.0 Safari/537.36 Edg/108.0.1462.42'
    }
    r = requests.get('https://oa.qianyibangong.com/p/221121/33cb60d609',headers=headers,verify=False)
    image_base64 = r.text
    # print(r.text)
    # print(type(image_base64))
    a = """
    
    
    """.strip()
    # a = image_base64
    if ',' in a:
        head,context=a.split(",")
    else:
        head = None
        context = a
    # 解码图片
    img_data = base64.b64decode(context)
    # imgdata = base64.b64decode(image_base64)
    # print(imgdata)
    # 将图片保存为文件


    with open("苹果爱薇.jpg", 'wb') as f:
        f.write(img_data)

    image = Image.open(BytesIO(img_data))
    image.show()

if __name__ == '__main__':
    main()